package com.gs.commentvl.dao;


import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;

import com.gs.commentvl.model.DomainObject;
import com.gs.commentvl.model.Member;

@Repository
public class MemberDaoImpl extends GenericDao<Member> implements MemberDao{
	
	private static final String MEMBER = "Mem_";
	
	@Autowired
	private RedisTemplate<String, Member> redisTemplate;
	
	
	@Override
	public void addMemeber(String userName, Member member) {
		redisTemplate.opsForHash().putAll(MEMBER + userName, member.toHashMap());		
	}

	@Override
	public Member getMemberByLogin(String userName, String pwd) {
		if (this.existKey(MEMBER + userName)){
			String password = (String) redisTemplate.opsForHash().get(MEMBER + userName, "password");
			if (pwd.equals(password)) {
				Map<Object, Object> map = redisTemplate.opsForHash().entries(MEMBER + userName);
				return this.convertMapToBean(map, Member.class);				
			}
		}		
		return null;
	}

	@Override
	public void addHash(String key, Map<String, String> Map) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Map<String, String> getHash(String key) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean existKey(String key) {
		return redisTemplate.hasKey(key);
		
	}

}